/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hearts;

import java.security.SecureRandom;
import java.util.ArrayList;

/**
 *
 * @author TAI
 */
public class computer extends player{
	public card passLeftMotRandomCard(){
		SecureRandom numGenerate=new SecureRandom();
		int random=0;
		while (random==0){
			random=numGenerate.nextInt(14);
		}
		return passLeftMotCard(random);
	}


	public card choiDauTien(boolean duocChonCo) {
		SecureRandom numGenerate=new SecureRandom();
		int random=0;
		while ((random==0)||(cardDaChoi[random]==true)||(danhSachCard[random].getID()==41)||
				((danhSachCard[random].kiemTraChatCo())&&(!duocChonCo))){
			random=numGenerate.nextInt(14);
		}
		cardDaChoi[random]=true;
		return danhSachCard[random];
	}


	public card choiSau(card c) {
		ArrayList<Integer> cungChat=new ArrayList<Integer>();
		for (int i=1;i<=13;i++)
			if ((cardDaChoi[i]==false)&&(danhSachCard[i].kiemTraCungChat(c))){
				cungChat.add(i);
			}
		if (cungChat.size()!=0){
			SecureRandom numGenerate=new SecureRandom();
			int random=0;
			random=numGenerate.nextInt(cungChat.size());
			cardDaChoi[cungChat.get(random)]=true;
			return danhSachCard[cungChat.get(random)];
		}
		else{
			return choiDauTien(true);
		}

	}

	public card choi2Chuon(){
		for (int i=1;i<=13;i++)
			if (danhSachCard[i].getID()==2)
			{
				cardDaChoi[i]=true;
				return danhSachCard[i];
			}
		return null;
	}


}
